﻿namespace BEGDC.CC.Web.UserControls.EV
{
    using System;
    using System.Collections;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using BEGDC.CC.BL.CCFlow.EV;
    using BEGDC.CC.BL.Common;
    using BEGDC.CC.BL.Common.Query;
    using BEGDC.CC.BL.Workflow;
    using BEGDC.CC.Entity;
    using BEGDC.CC.ExcelTool;
    using BEGDC.CC.Web.UserControls.CV;
    using BEGDC.Utility.Castle;
    using BEGDC.Utility.ExceptionManagement;
    using Nullables;

    /// <summary>
    ///		Summary description for MeetingMinutes.
    /// </summary>
    public class MeetingMinutes : BaseEV
    {
        protected System.Web.UI.WebControls.Button ibtnQuery;
        protected System.Web.UI.WebControls.Button ibtnReject;
        protected System.Web.UI.WebControls.Button ibtnSubmit;
        protected System.Web.UI.WebControls.Button ibtnCheck;
        protected System.Web.UI.WebControls.Button ibtnSave;
        protected System.Web.UI.WebControls.Button ibtnReply;

        protected System.Web.UI.WebControls.TextBox txtVenue;
        protected System.Web.UI.WebControls.TextBox txtTime;
        protected System.Web.UI.WebControls.TextBox txtContent;
        protected System.Web.UI.WebControls.TextBox txtVisitingPurpose;
        protected System.Web.UI.WebControls.DataGrid dtGridAP;
        protected System.Web.UI.WebControls.DataGrid dtGridASBAttendee;
        protected System.Web.UI.WebControls.DataGrid dtGridCustomerAttendee;
        protected System.Web.UI.WebControls.Button imgAddAP;
        protected System.Web.UI.HtmlControls.HtmlGenericControl proposedDate;
        protected System.Web.UI.HtmlControls.HtmlAnchor ibtnExport;
        protected System.Web.UI.HtmlControls.HtmlGenericControl apHint;
        protected System.Web.UI.WebControls.Button btnAddASBAttendee;
        protected System.Web.UI.WebControls.Button imgDelCustAttendee;
        protected System.Web.UI.WebControls.Label lblVenueValue;
        protected System.Web.UI.WebControls.Label lblDate;
        protected System.Web.UI.HtmlControls.HtmlTableCell VisitingPurpose;
        protected System.Web.UI.HtmlControls.HtmlTableCell MeetingContent;
        protected System.Web.UI.WebControls.TextBox tbOperationFlag;
        protected System.Web.UI.WebControls.TextBox tbOperationContent;
        protected System.Web.UI.WebControls.TextBox tbComment;
        protected BEGDC.CC.Web.UserControls.CV.CVPrintCtrl CVPrintCtrl1;

        #region Property
        private object MeetingAttendeeList
        {
            get
            {
                return Session["MeetingAttendee" + this.MeetingID];
            }
            set
            {
                Session["MeetingAttendee" + this.MeetingID] = value;
            }
        }
        protected EVMeeting EVMeeting
        {
            get
            {
                if (Session[base.AppID + "MeetingMinutes"] == null)
                    return null;
                else
                    return Session[base.AppID + "MeetingMinutes"] as EVMeeting;
            }
            set
            {
                Session[base.AppID + "MeetingMinutes"] = value;
            }
        }

        protected int MeetingID
        {
            get
            {
                if (EVMeeting == null)
                    return 0;
                else
                    return EVMeeting.Id;
            }
        }
        protected string State
        {
            get
            {
                return Request.QueryString["State"].ToString();
            }
        }
        protected string Step
        {
            get
            {
                IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;
                FlowInstance flowInstance = queryService.QueryFlowInstance(this.AppID);
                if (flowInstance == null)
                    return "Close";
                else
                    return flowInstance.CurrentActiveStep.StepCode;
            }
        }

        //		private Accessibility access = Accessibility.None;

        #endregion
        private void Page_Load(object sender, System.EventArgs e)
        {

            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                base.InitCommonData();

                MeetingAttendeeList = null;

                InitAppData();

                ControlStatusSetting();

            }

            InitMeetingAttendee();
            InitAPList();

            if (this.Access != null)
            {
                ControlVisibleSetting(((EVAccessControl)Access).IsReadOnlyForApp);
            }

            this.ibtnSubmit.Attributes["onclick"] = "javascript:OnSubmit();";
            this.ibtnCheck.Attributes["onclick"] = "javascript:OnSubmit();";
            this.ibtnReject.Attributes["onclick"] = "javascript:OnReject();";
            this.ibtnQuery.Attributes.Add("onclick", "javascript:OpenQueryPane(" + Request.QueryString["flowid"] + ")");
            this.ibtnSave.Attributes["onclick"] = "javascript:OnSave();";
            this.ibtnReply.Attributes.Add("onclick", "javascript:OpenReplyPane(" + Request.QueryString["flowid"] + ")");

            this.btnAddASBAttendee.Attributes["onclick"] = "javascript:AddAttendee('Yes');";
            this.imgAddAP.Attributes["onclick"] = "javascript:AddActionPoint(0);";

            if (this.MeetingID <= 0)
            {
                this.ibtnExport.Visible = false;
                this.CVPrintCtrl1.Visible = false;
            }
            else
            {
                this.ibtnExport.Visible = true;
                this.CVPrintCtrl1.Visible = true;
                this.ibtnExport.HRef = "~/workflow/ExcelExport.aspx?MMID=" + this.MeetingID.ToString();
            }


        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ibtnReply.Click += new EventHandler(ibtnReply_Click);
            this.ibtnCheck.Click += new EventHandler(ibtnCheck_Click);
            this.ibtnSubmit.Click += new EventHandler(ibtnSubmit_Click);
            this.ibtnQuery.Click += new EventHandler(ibtnQuery_Click);
            this.ibtnReject.Click += new EventHandler(ibtnReject_Click);
            this.ibtnSave.Click += new EventHandler(ibtnSave_Click);
            this.dtGridASBAttendee.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dtGridASBAttendee_ItemCommand);
            this.dtGridASBAttendee.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dtGridASBAttendee_ItemDataBound);
            this.dtGridCustomerAttendee.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dtGridCustomerAttendee_ItemCommand);
            this.dtGridCustomerAttendee.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dtGridCustomerAttendee_ItemDataBound);
            this.dtGridAP.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dtGridAP_ItemCommand);
            this.dtGridAP.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dtGridAP_ItemDataBound);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void ControlVisibleSetting(bool isReadonly)
        {
            if (!isReadonly)
                isReadonly = !this.IsCurrentStep(WorkTransition.EV_CODStaffCheckMM) & !this.IsCurrentStep(WorkTransition.EV_MeetingMinutes);
            if (isReadonly)
            {
                this.txtTime.Visible = false;
                this.txtVenue.Visible = false;
                if (txtContent.Text + string.Empty != string.Empty)
                    this.MeetingContent.InnerHtml = txtContent.Text.Replace("\r\n", "<br>");
                this.txtContent.Visible = false;
                if (this.txtVisitingPurpose.Text + string.Empty != string.Empty)
                    this.VisitingPurpose.InnerHtml = this.txtVisitingPurpose.Text.Replace("\r\n", "<br>");
                this.txtVisitingPurpose.Visible = false;
                this.imgAddAP.Visible = false;
                this.btnAddASBAttendee.Visible = false;
                this.imgDelCustAttendee.Visible = false;
                //this.proposedDate.Visible = false;
                this.proposedDate.Visible = true;
                this.dtGridCustomerAttendee.Columns[5].Visible = false;
                this.dtGridASBAttendee.Columns[5].Visible = false;
                this.dtGridAP.Columns[6].Visible = false;
            }
            else
            {
                this.lblDate.Visible = false;
                this.lblVenueValue.Visible = false;
                this.txtVisitingPurpose.Visible = true;
                this.txtContent.Visible = true;
            }
        }
        protected override void ControlStatusSetting()
        {
            //if (this.Step == WorkTransition.EV_CODStaffCheckMM || this.State == EVTransitionList.Query)
            if (this.Step == WorkTransition.EV_CODStaffCheckMM)
            {
                this.imgAddAP.Visible = false;
            }

            ButtonStatusSetting();
        }

        protected override void ButtonStatusSetting()
        {
            bool isActiveStep = this.IsCurrentStep(WorkTransition.EV_CODStaffCheckMM) | this.IsCurrentStep(WorkTransition.EV_MeetingMinutes);
            if (!isActiveStep)
            {
                this.ibtnSubmit.Visible = false;
                this.ibtnQuery.Visible = false;
                this.ibtnSave.Visible = false;
                this.ibtnReply.Visible = false;
                this.ibtnCheck.Visible = false;
                this.ibtnReject.Visible = false;
                this.ibtnExport.Visible = false;
                this.CVPrintCtrl1.Visible = false;
            }
            else
            {
                if (this.Access != null)
                {
                    if (Access.IsHideAllButton)
                    {
                        this.ibtnSubmit.Visible = false;
                        this.ibtnQuery.Visible = false;
                        this.ibtnSave.Visible = false;
                        this.ibtnReply.Visible = false;
                        this.ibtnCheck.Visible = false;
                        this.ibtnReject.Visible = false;
                        this.ibtnExport.Visible = false;
                        this.CVPrintCtrl1.Visible = false;
                    }
                    else if (Access.IsQuery)
                    {
                        this.ibtnSubmit.Visible = false;
                        this.ibtnSave.Visible = true;
                        this.ibtnCheck.Visible = false;
                        this.ibtnQuery.Visible = false;
                        this.ibtnReject.Visible = false;
                        this.ibtnExport.Visible = false;
                        this.CVPrintCtrl1.Visible = false;
                        this.ibtnReply.Visible = true;

                        //						this.dtGridASBAttendee.Columns[5].Visible = false;
                        //						this.dtGridCustomerAttendee.Columns[5].Visible = false;
                        //						this.dtGridAP.Columns[5].Visible = false;
                    }
                    else
                    {
                        this.ibtnSubmit.Visible = Access.IsButtonVisible(EVTransitionList.Submit);
                        this.ibtnCheck.Visible = Access.IsButtonVisible(EVTransitionList.Check);
                        this.ibtnReject.Visible = Access.IsButtonVisible(EVTransitionList.Reject);
                        this.ibtnQuery.Visible = Access.IsButtonVisible(EVTransitionList.Query);
                        this.ibtnReply.Visible = false;
                    }

                }
            }
        }


        protected override void DisableChildrenControls(System.Web.UI.Control parentControl)
        {
            foreach (System.Web.UI.Control child in parentControl.Controls)
            {
                DisableChildrenControls(child);
                Type type = child.GetType();
                if (child.ID != null)
                {
                    if (child.ID.IndexOf("btnEditAP") >= 0)
                    {
                        continue;
                    }
                }
                if (BaseCtrl.IsClassOf(type, typeof(System.Web.UI.WebControls.TextBox))
                    || IsClassOf(type, typeof(System.Web.UI.WebControls.ListBox))
                    || IsClassOf(type, typeof(System.Web.UI.WebControls.DropDownList))
                    || IsClassOf(type, typeof(System.Web.UI.WebControls.CheckBox))
                    || IsClassOf(type, typeof(System.Web.UI.WebControls.RadioButtonList))
                    || IsClassOf(type, typeof(System.Web.UI.WebControls.RadioButton)))
                {
                    System.Web.UI.WebControls.WebControl control = (System.Web.UI.WebControls.WebControl)child;
                    control.Enabled = false;
                    continue;
                }
                if (BaseCtrl.IsClassOf(type, typeof(System.Web.UI.WebControls.ImageButton))
                    || IsClassOf(type, typeof(System.Web.UI.WebControls.Button)))
                {
                    child.Visible = false;
                    continue;
                }
                if (BaseCtrl.IsClassOf(type, typeof(System.Web.UI.HtmlControls.HtmlImage)))
                {
                    System.Web.UI.HtmlControls.HtmlControl control = (System.Web.UI.HtmlControls.HtmlControl)child;
                    control.Disabled = true;
                    continue;
                }
            }

        }

        private void InitAppData()
        {
            InitEVMeeting();
        }

        private void InitEVMeeting()
        {
            try
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                IList meetingList = evService.GetEVMeetingByAppID(base.AppID);
                if (meetingList != null && meetingList.Count > 0)
                {
                    this.EVMeeting = meetingList[0] as EVMeeting;
                }
                if (this.EVMeeting != null)
                {
                    this.apHint.Attributes["style"] = "display:none";

                    this.txtContent.Text = EVMeeting.Content;
                    this.txtVenue.Text = EVMeeting.Venue;
                    this.lblVenueValue.Text = EVMeeting.Venue;
                    if (this.EVMeeting.MeetingDate != Nullables.NullableDateTime.Default)
                    {
                        this.txtTime.Text = EVMeeting.MeetingDate.Value.ToString("MM/dd/yyyy");
                        this.lblDate.Text = this.txtTime.Text;
                    }
                    this.txtVisitingPurpose.Text = EVMeeting.VisitingPurpose;
                }
                else
                {
                    this.ibtnExport.Visible = false;
                    this.CVPrintCtrl1.Visible = false;
                }
            }
            catch (GDCException gdcEx)
            {
            }
        }
        private void InitMeetingAttendee()
        {
            try
            {
                DataTable MeetingAttendee = null;
                if (Session["MeetingAttendee" + this.MeetingID] != null)
                {
                    MeetingAttendee = (DataTable)Session["MeetingAttendee" + this.MeetingID];
                }
                else
                {
                    if (this.MeetingID > 0)
                    {
                        IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                        MeetingAttendee = queryService.QueryEVMeetingAttendee(this.MeetingID);
                    }
                    if (MeetingAttendee == null || MeetingAttendee.Rows.Count == 0)
                    {
                        MeetingAttendee = new DataTable();
                        MeetingAttendee.Columns.Add(new DataColumn("RowId", typeof(System.String)));
                        MeetingAttendee.Columns.Add(new DataColumn("AttendeeID", typeof(System.String)));
                        MeetingAttendee.Columns.Add(new DataColumn("NameCN", typeof(System.String)));
                        MeetingAttendee.Columns.Add(new DataColumn("NameEN", typeof(System.String)));
                        MeetingAttendee.Columns.Add(new DataColumn("Company", typeof(System.String)));
                        MeetingAttendee.Columns.Add(new DataColumn("Department", typeof(System.String)));
                        MeetingAttendee.Columns.Add(new DataColumn("Title", typeof(System.String)));
                    }
                    Session["MeetingAttendee" + this.MeetingID] = SetRowID(MeetingAttendee);
                }

                MeetingAttendee.DefaultView.RowFilter = "Company='ASB'";
                this.dtGridASBAttendee.DataSource = MeetingAttendee.DefaultView;
                this.dtGridASBAttendee.DataBind();

                MeetingAttendee.DefaultView.RowFilter = "Company<>'ASB'";
                this.dtGridCustomerAttendee.DataSource = MeetingAttendee.DefaultView;
                this.dtGridCustomerAttendee.DataBind();
            }
            catch (GDCException gdcEx)
            {
            }
        }

        private DataTable SetRowID(DataTable table)
        {
            if (table != null && table.Rows.Count > 0)
                for (int i = 1; i <= table.Rows.Count; i++)
                {
                    table.Rows[i - 1][0] = i.ToString();
                }
            return table;
        }

        private void InitAPList()
        {
            try
            {
                IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
                DataTable dtTable = queryService.QueryAPListByMeetingID(this.MeetingID);

                this.dtGridAP.DataSource = dtTable;
                this.dtGridAP.DataBind();
            }
            catch (GDCException gdcEx)
            {

            }
        }

        private void BuildObj2Save()
        {
            if (this.EVMeeting == null)
            {
                this.EVMeeting = new EVMeeting();
            }
            EVMeeting.Venue = this.txtVenue.Text;
            this.EVMeeting.Application = base.Application;
            if (this.txtTime.Text != string.Empty)
            {
                DateTime date = Convert.ToDateTime(this.txtTime.Text);
                EVMeeting.MeetingDate = new NullableDateTime(date);
            }
            EVMeeting.VisitingPurpose = this.txtVisitingPurpose.Text;
            EVMeeting.Content = this.txtContent.Text.ToString();
        }

        private void BuildAttendee(ref IList attendeeList)
        {
            string strTemp;
            try
            {
                DataTable table = null;
                if (MeetingAttendeeList != null)
                    table = (DataTable)MeetingAttendeeList;
                if (table != null && table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        Entity.EVMeetingAttendee attendee = new EVMeetingAttendee();

                        attendee.EVMeeting = this.EVMeeting;
                        attendee.NameEN = table.Rows[i]["NameEN"].ToString();
                        attendee.NameCN = table.Rows[i]["NameCN"].ToString();
                        attendee.Title = table.Rows[i]["Title"].ToString();
                        attendee.Company = table.Rows[i]["Company"].ToString();
                        attendee.Department = table.Rows[i]["Department"].ToString();

                        attendeeList.Add(attendee);
                    }
                }
            }
            catch (Exception exp)
            {
                strTemp = exp.Message;
            }
        }
        private void BuildAPList(ref IList apList)
        {
            DataTable table = (DataTable)this.dtGridAP.DataSource;
            Entity.ActionPoint ap = null;
            if (table != null)
            {
                foreach (DataRow row in table.Rows)
                {
                    ap = new Entity.ActionPoint();
                    ap.Id = Convert.ToInt32(row["APID"]);

                    apList.Add(ap);
                }
            }
        }
        void ibtnSave_Click(object sender, EventArgs e)
        {
            try
            {
                this.ibtnExport.Visible = true;
                this.CVPrintCtrl1.Visible = true;
                this.BuildObj2Save();
                IList attendeeList = new ArrayList();
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;

                this.BuildAttendee(ref attendeeList);
                evService.SaveMeetingMinutes(this.EVMeeting, attendeeList, null);

                if (this.EVMeeting.Id <= 0)
                {
                    IList list = evService.GetEVMeetingByAppID(this.Application.Id);
                    if (list.Count > 0)
                    {
                        EVMeeting mm = (EVMeeting)list;
                        this.EVMeeting.Id = mm.Id;
                        this.ibtnExport.HRef = "~/workflow/ExcelExport.aspx?MMID=";
                    }
                }
                else
                {
                    this.ibtnExport.HRef = "~/workflow/ExcelExport.aspx?MMID=" + this.EVMeeting.Id.ToString();
                }


                Session["AppID"] = this.Application.Id;

                string url = string.Empty + Request.Form["tbURL"];
                string script = "<script>";
                if (url == string.Empty)
                    script += "VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');";
                if (url != string.Empty)
                {
                    if (url.IndexOf("AppID") == -1)
                        url = url.Substring(0, url.IndexOf("?") + 1) + "AppID=" + this.Application.Id + "&" + url.Substring(url.IndexOf("?") + 1);
                    script += "window.location.href='" + url + "'";
                }
                else
                {
                    url = Request.Url.AbsoluteUri;
                    if (url.ToUpper().IndexOf("APPID") == -1)
                    {
                        url = url.Substring(0, url.IndexOf("?") + 1) + "AppID=" + this.Application.Id + "&" + url.Substring(url.IndexOf("?") + 1);
                        script += "window.location.href='" + url + "'";
                    }
                }
                script += "</script>";

                Page.RegisterClientScriptBlock("", script);

                //				Page.RegisterClientScriptBlock("","<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "')</script>");
            }
            catch (Exception exp)
            {
                int a = 1;
            }
        }

        void ibtnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                this.BuildObj2Save();
                IList attendeeList = new ArrayList();
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                this.BuildAttendee(ref attendeeList);

                IList apList = new ArrayList();
                this.BuildAPList(ref apList);

                evService.SubmitMeetingMinutes(this.EVMeeting, attendeeList, apList, null);
                Page.RegisterClientScriptBlock("", "<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');window.close();</script>");
            }
            catch (GDCException gdcEx)
            {
                throw gdcEx;
            }

            //WebUtility.Go2SuccessPage(this.Page);

        }

        private void ibtnDrawback_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            try
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.Drawback(this.Application, null);
                Response.Write("<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CM001 + "');</script>");
            }
            catch (BEGDC.Utility.ExceptionManagement.GDCException gdcEx)
            {

            }
        }

        #region DataGrid Bind&Command operations

        private void dtGridASBAttendee_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                ImageButton Btn_Edit = (ImageButton)e.Item.Cells[5].FindControl("btn_ASBAttendeeAdd");
                string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenMeetingAttendee('" + ItemId + "');");

                ImageButton btnDel = (ImageButton)e.Item.Cells[5].FindControl("btn_CusAttendeeDel");
                btnDel.Attributes.Add("onclick", "return confirm('Are you sure to delete this item?')");
            }
        }

        private void dtGridCustomerAttendee_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                ImageButton Btn_Edit = (ImageButton)e.Item.Cells[5].FindControl("ibtnAddCustAttendee");
                string ItemId = e.Item.Cells[0].Text.ToString();
                Btn_Edit.Attributes.Add("onclick", "OpenMeetingAttendee('" + ItemId + "');");

                ImageButton btnDel = (ImageButton)e.Item.Cells[5].FindControl("ibtnDelCustAttendee");
                btnDel.Attributes.Add("onclick", "return confirm('Are you sure to delete this item?')");
            }

        }

        private void dtGridASBAttendee_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                string itemId = e.Item.Cells[0].Text;
                DataTable table = (DataTable)Session["MeetingAttendee" + this.MeetingID];
                if (table != null)
                {

                    table.Rows.Remove(table.Rows[Convert.ToInt32(itemId) - 1]);

                    this.dtGridASBAttendee.DataSource = this.SetRowID(table);
                    this.dtGridASBAttendee.DataBind();
                    MeetingAttendeeList = table;

                    InitMeetingAttendee();
                }
            }
        }

        private void dtGridCustomerAttendee_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                string itemId = e.Item.Cells[0].Text;
                DataTable table = (DataTable)Session["MeetingAttendee" + this.MeetingID];
                if (table != null)
                {
                    table.Rows.Remove(table.Rows[Convert.ToInt32(itemId) - 1]);

                    this.dtGridCustomerAttendee.DataSource = this.SetRowID(table);
                    this.dtGridCustomerAttendee.DataBind();
                    MeetingAttendeeList = table;
                    InitMeetingAttendee();
                }
            }
        }

        private void dtGridAP_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                ImageButton Btn_Edit = (ImageButton)e.Item.Cells[5].FindControl("btnEditAP");
                string ItemId = e.Item.Cells[0].Text.ToString();
                string statu = "Full";
                //				if (access == Accessibility.Readonly)
                //				{
                //					statu = "Readonly";
                //				}
                if (((EVAccessControl)Access).IsReadOnlyForApp || (!this.IsCurrentStep(WorkTransition.EV_CODStaffCheckMM) & !this.IsCurrentStep(WorkTransition.EV_MeetingMinutes)))
                {
                    statu = "Readonly";
                }
                Btn_Edit.Attributes.Add("onclick", "AddActionPoint('" + ItemId + "','" + statu + "');");

                ImageButton btnDel = (ImageButton)e.Item.Cells[6].FindControl("btnDeleAP");
                btnDel.Attributes.Add("onclick", "return confirm('This item will be delete permantly,Are you sure ?')");
            }
        }

        private void dtGridAP_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                string itemId = e.Item.Cells[0].Text;
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.DeleteAP(Convert.ToInt32(itemId));

                InitAPList();
            }
        }

        #endregion

        //		private void ibtnExport_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        //		{
        //			try
        //			{
        //				ExcelTool.ICCExcelExport exportEVMeeting=new ExcelTool.ExportEVMeeting();
        //				exportEVMeeting.Export(this.Page, this.MeetingID );
        //			}
        //			catch
        //			{
        //				Page.RegisterClientScriptBlock("","<script>alert('" + BEGDC.CC.Resource.ErrorMessage.Export_0001 + "');</script>");
        //			}
        //		}

        void ibtnCheck_Click(object sender, EventArgs e)
        {
            try
            {
                this.BuildObj2Save();
                IList attendeeList = new ArrayList();
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                this.BuildAttendee(ref attendeeList);

                IList apList = new ArrayList();
                this.BuildAPList(ref apList);

                evService.CheckMeetingMinutes(this.EVMeeting, attendeeList, apList, null);
                Page.RegisterClientScriptBlock("", "<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');window.close();</script>");
            }
            catch (GDCException gdcEx)
            {
                throw gdcEx;
            }
        }

        void ibtnReply_Click(object sender, EventArgs e)
        {
            IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
            if (this.tbOperationFlag.Text == "reply")
            {
                this.ibtnExport.Visible = true;
                this.CVPrintCtrl1.Visible = true;
                this.BuildObj2Save();
                IList attendeeList = new ArrayList();

                this.BuildAttendee(ref attendeeList);
                evService.SaveMeetingMinutes(this.EVMeeting, attendeeList, null);

                evService.ReplyQuery(Convert.ToInt64(Request.QueryString["flowid"]), this.tbOperationContent.Text);
                evService.StartActionPoint(this.EVMeeting);
                Page.RegisterClientScriptBlock("", "<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');window.close();</script>");
            }
        }

        void ibtnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.tbOperationFlag.Text == "query")
                {
                    IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                    string comment = string.Empty;
                    if (Session["Comment"] != null)
                        comment = Session["Comment"].ToString();
                    evService.Query(Convert.ToInt64(Request.QueryString["flowid"]), this.tbOperationContent.Text, comment);
                    Page.RegisterClientScriptBlock("", "<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');window.close();</script>");
                }
            }
            catch
            {
            }
        }

        void ibtnReject_Click(object sender, EventArgs e)
        {
            try
            {
                IEV evService = AppContainer.Instance[ServiceConst.EVService] as IEV;
                evService.RejectCheckApp(this.Application, WebUtility.DeCodeString(this.Server, this.tbComment.Text));
                Page.RegisterClientScriptBlock("", "<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');window.close();</script>");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
